using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class RankPanel : BasePanel<RankPanel>
{
    public CustomGUIButton btnClose;

    private List<CustomGUILabel> labName = new List<CustomGUILabel>();
    private List<CustomGUILabel> labTime = new List<CustomGUILabel>();
    private List<CustomGUILabel> labScore = new List<CustomGUILabel>();
    public const int rankNums=10;

    private void Start()
    {
        for(int i = 1; i <= rankNums; i++)
        {
            labName.Add(this.transform.Find("Name/labName" + i).GetComponent<CustomGUILabel>());
            labTime.Add(this.transform.Find("Time/labTime" + i).GetComponent<CustomGUILabel>());
            labScore.Add(this.transform.Find("Score/labScore" + i).GetComponent<CustomGUILabel>());

        }

        btnClose.clickEvent += () =>
        {
            HideMe();
            BeginPanel.Instance.ShowMe();
        };
        GameDataMgr.Instance.AddRankInfo("jack", 50, 8453);

        HideMe();
        
    }

    public override void ShowMe()
    {
        base.ShowMe();
        UpdatePanelInfo();
    }

    private void UpdatePanelInfo()
    {
        
        List<RankInfo> list = GameDataMgr.Instance.rankData.list;
        for(int i = 0; i < list.Count; i++)
        {
            labName[i].content.text = list[i].name;
            labScore[i].content.text = list[i].score.ToString();

            float time = list[i].time;

            labTime[i].content.text = TimeSpan.FromSeconds(time).ToString(@"hh\:mm\:ss");
        }

    }

}
